﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="NFL.UI.testharness" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>NFL SCORES</title>
    
    <script src="Scripts/jquery-2.1.1.min.js"></script>
    <script>
        function ReloadPage() {
            <%= ClientScript.GetPostBackEventReference(ddlDivision, "") %>
        };

        $(document).ready(function () {
            setInterval(function () {
                ReloadPage();
            }, 180000);
        });

        $(function () {
            var cdt = new Date();
            var formateddatetime = cdt.toLocaleDateString() + '  ' + cdt.toLocaleTimeString();
            $("#currentdatetime").text(formateddatetime);

            // Do customizations
            //SetDivision();
            GetDivisionUsers($('#ddlDivision').val());
            HighlightUser();
        });

        function SetDivision() {
            if (localStorage) {
                var division = localStorage.getItem('division');
                if (division != null) {
                    $('#ddlDivision').val(division);
                }
            }
        }
        

        function HighlightUser() {
            if (localStorage) {
                var userid = localStorage.getItem('userid');
                if (userid != null) {
                    $("#gvScores tr:contains('" + userid + "')").css("font-size", "x-large");
                }
            }
        }

        function GetDivisionUsers(division) {
            if (localStorage) {
                if (localStorage.getItem('grid') != null) {
                    var data = JSON.parse(localStorage.getItem('grid'));

                    // Sort the data descending because its a string value 
                    data.sort(function (x, y) {
                        return parseInt(y.userid) - parseInt(x.userid);
                    });

                    $.each(data, function (i, item) {
                        if (data[i].division == division) {
                            $("#gvScores td:nth-child(1):contains('" + item.userid + "')").html(function(index,html){
                                return html.replace(item.userid, item.name);
                            });
                        }
                    });
                }
            }
        }

        function toggleimages() {
            $('#customsettings').toggle("slow");
            var newText = $('#showcustomsettings').text() == "View" ? "Hide" : "View";
            $('#showcustomsettings').text(newText);

        }

    </script>
    <%--<style>
        .customsettings {
            display: none
        }

    </style>--%>
    <style>
        A {
            text-decoration: none;
            font-size: x-small;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">

    <div>
        <span style="font: bold; font-size:larger;">Week:&nbsp;<%= this.WeekID %></span>
        &nbsp;&nbsp;&nbsp;
        Division: 
        <asp:DropDownList ID="ddlDivision" runat="server" OnSelectedIndexChanged="ddlDivision_SelectedIndexChanged" AutoPostBack="True">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
        </asp:DropDownList>
        &nbsp;&nbsp;&nbsp;
        <img src="images/greensquare.png" /> &nbsp;=&nbsp;WIN
        &nbsp;&nbsp;
        <img src="images/redsquare.png" /> &nbsp;=&nbsp;LOSS
    </div>

    <div>
        <asp:GridView ID="gvScores" runat="server" OnRowDataBound="gvScores_RowDataBound" ViewStateMode="Disabled">
            <emptydatatemplate>
                No Data Available.  Check Back Later.
            </emptydatatemplate> 
        </asp:GridView>
    </div>

    <div>
        <span id="currentdatetime" style="font-size: smaller;"></span>
    </div>

    <div>
        <span style="font-size: smaller;">Games refreshed every 3 minutes on game days</span>
    </div>

    <div>
        <span style="font-size: smaller;">Web URL: <%= HttpUtility.UrlPathEncode("http://itsapptime.com/NFL") %></span>
    </div>
    <div>
        <a href='settings.html' id='showcustomsettings'>(Custom Settings)</a>
          <%--<a href='javascript:void(0);return false;' id='showcustomsettings' onclick="togglesettings()">Custom Settings</a>--%>
    </div>
    <%--<div id="customsettings">

    </div>--%>
    </form>
</body>
</html>
